package com.mlog.njyjy.ndop.share.kafka.oauth;

/**
 * <p>
 * .
 * </p>
 *
 * @author <a href="mailto:yingxiufeng@mlogcn.com">alex</a>
 * @version v1.0, 2020/7/16
 */
public final class EnvUtil {

    public static final String TOKEN_URL = "token.url";


    /**
     * 获取环境变量
     *
     * @param envName
     * @param defaultValue
     * @return
     */
    public static Object getEnvironmentVariables(String envName, Object defaultValue) {
        Object result = null;
        String env = System.getenv(envName);
        if (env == null) {
            result = defaultValue;
        } else {
            if (defaultValue instanceof Boolean) {
                result = Boolean.valueOf(env);
            } else if (defaultValue instanceof Integer) {
                result = Integer.valueOf(env);
            } else if (defaultValue instanceof Double) {
                result = Double.valueOf(env);
            } else if (defaultValue instanceof Float) {
                result = Float.valueOf(env);
            } else {
                result = env;
            }
        }
        return result;
    }

    public static String upperFirst(String str) {
        char[] chars = str.toCharArray();
        if (chars[0] >= 'a' && chars[0] <= 'z') {
            chars[0] = (char) (chars[0] - 32);
        }
        return new String(chars);
    }
}
